package com.k.demo.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.k.demo.entity.PowerDistribution;
import com.k.demo.mapper.PowerDistributionMapper;
import com.k.demo.service.PowerDistributionService;

@Service
public class PowerDistributionServiceImpl implements PowerDistributionService {
	
	@Autowired
	private PowerDistributionMapper powerdistributionMapper;
	@Override
	public List<PowerDistribution> getPowerDistributeByUserId(int user_id) {
		// TODO Auto-generated method stub
		return powerdistributionMapper.selectAllByUserId(user_id);
	}
	@Override
	public int deletePowerFromUser(int user_id, List<Integer> power_id) {
		// TODO Auto-generated method stub
		for(int i : power_id) {
			powerdistributionMapper.delete(user_id, i);
		}
		return power_id.size();
	}
	@Override
	public int grantPowerToUser(int user_id, List<Integer> power_id) {
		// TODO Auto-generated method stub
		for(int i : power_id) {
			powerdistributionMapper.insert(user_id, i);
		}
		return power_id.size();
	}
	@Override
	public int clearPower(int user_id) {
		// TODO Auto-generated method stub
		return powerdistributionMapper.deleteUserPower(user_id);
	}
	@Override
	public List<PowerDistribution> getPowerDistributeByPowerId(int power_id) {
		// TODO Auto-generated method stub
		return powerdistributionMapper.selectAllByPowerId(power_id);
	}
	@Override
	public List<PowerDistribution> getByUserIdInList(List<Integer> user_id) {
		// TODO Auto-generated method stub
		return powerdistributionMapper.selectByUserIdInList(user_id);
	}
	@Override
	public List<Integer> getAllUserId() {
		// TODO Auto-generated method stub
		return powerdistributionMapper.selectAllUserId();
	}

}
